const jwt = require("jsonwebtoken"),
    dayjs = require("dayjs");

const userService = require("../service/userService"),
    utils = require("../utils");

class UserController {
    // 获取用户信息
    async getInfo(req, res, next) {
        try {
            const jwtData = await jwt.verify(req.headers.authorization, process.env.SECRET_KEY);

            const { password, ...newData } = await userService.find(jwtData);
            res.send(
                utils.msgSuccess({
                    data: {
                        ...newData,
                        login_time: dayjs(newData.login_time).format("YYYY-MM-DD HH:mm:ss"),
                    },
                })
            );
        } catch (error) {
            next(error);
        }
    }
}

module.exports = new UserController();
